<?php

namespace App\Http\Controllers;

use App\Blog;
use Illuminate\Http\Request;

class BlogController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        return view('pages.blog',[
            'blog' => Blog::with(['craftsman:id,shop_name','zone'])->paginate(10)
        ]);
    }

    public function update(Request $request, Blog $blog)
    {
        if($request->action){
            $blog->delete();
            return back()->withStatus(__('博客移除成功'));
        }elseif($request->recommend){
            $blog->update(['recommend' => 1]);
            return back()->withStatus(__('博客置精成功'));
        }else{
            $blog->update(['recommend' => 0]);
            return back()->withStatus(__('取消博客置精成功'));
        }

    }

}
